GenerativeComponents Help

The DataExporter Node

Like a DataImporter, a DataExporter connects to an external database. However, whereas a DataImporter is designed to populate another node from the database, a DataExporter is designed to populate the database from another node.

A DataExporter node has three techniques, which differ depending on how you want to connect to the database, and how you want to provide the data to that database.

The techniques are:

ByDatabase - technique

Generally, this technique is for writing data to a database that resides in a single file on your local computer; for example, an Access database.

The following properties define this technique.

DatabaseType: DatabaseType

The type of the database. One of the enumerated values Access, CommaSeparatedText, or SqlServerLocalDB.

(A CommaSeparatedText database is a plain text file in which the first line comprises a list of column names separated by commas, and each of the remaining lines comprises a list of values separated by commas.)

FilePath: string

The full path and file name of the database file. (Remember that you can enter this value by using the Expression Builder's file browser.)

SqlSelectCommand: string

A Transact-SQL SELECT command that defines how the property values being given to the DataExporter will correlate with the data being written to the database.

Even though a DataExporter is intended to update the database, this SELECT command is composed just as it is with a DataImporter. (Internally, ADO.NET's CommandBuilder class extrapolates an update command from your SELECT command.)

Here are some examples:
'SELECT * FROM myTable'

Populate the database table, 'myTable', from the given child nodes. The names of all of the columns in 'myTable' will be matched with the names of the corresponding properties of the child nodes.

(In the case of a CommaSeparatedText type database, the table name would be the name of the text file, including the '.txt' extension.)

'SELECT X, Y, Z FROM myTable'
Populate the database table, 'myTable', from the given child nodes; specifically, populate the columns named 'X', 'Y', and 'Z' with the properties 'X', 'Y' and 'Z' of the child nodes.
'SELECT ResultX AS X, ResultY As Y, ResultZ AS Z FROM myTable'

Populate the database table, 'myTable', from the given child nodes; specifically, populate the columns named 'ResultX', 'ResultY', and 'ResultZ' from the properties 'X', 'Y' and 'Z' of the child nodes.

Note: The full formulation of a SELECT command is beyond the scope of this document. For more information, please consult documentation for Microsoft's Transact-SQL language.

Node: Node or Node[]

The value of this property can be either a single node, or a list of nodes. For each given node, the property values of its child nodes will be written to the database.

The simplest situation is when the next property, ProcessEachChildNode, is left empty (null). In that case, the child nodes are processed one by one, and a row of data is written for each child node.

The data row is populated from the child node's properties, by matching up the child node's property names with the data column names.

ProcessEachChildNode: function – optional

A GCScript function that defines precisely how the data should be written, for each child node.

The preceding section describes the simple case when this function is left empty (null): The data rows are created by matching the data column names with the child node's property names. However, when this function is provided, the data rows are not created automatically. Rather, it becomes the responsibility of this function to create each data row, and assign its column values appropriately.

The given function must be of this general form:
void function(Node childNode, DataTable tbl)
{
    // Alternately, the argument, childNode, may be declared
    // to be of the same type as the actual child node (such
    // as ‘Point’).
    :
}
For example:
void function(Point childNode, DataTable tbl)
{
    if (childNode.Z < 3.7)
    {
        DataRow row = tbl.NewRow();
        row.X = childNode.X * 2;
        row.Y = childNode.Y;
    }
}
DataTable and DataRow are predefined types of the GCScript language. For more information, see Section II, GCScript Classes (below).

ByTable - technique

Generally, this technique is for writing data to a simple text file, when the power of a SELECT statement is not needed.

Currently, this technique supports only one file format, which is the native XML format of ADO.NET's DataSet class. Future versions of GC may support additional formats.
Note: You can write a comma-delimited text file with the ByDatabase technique, described above.
The following properties define this technique.

TableType: DataTableType

Currently, there is only one possible value, XmlWithSchema.

FilePath: string

The full path and file name of the text file.
Remember: You can enter this value by using the Expression Builder's file browser.

ColumnTypes: Type[] - optional

ColumnNames: string[] - optional

ColumnWidths: int[] - optional

This set of optional properties serves two purposes:
  1. If this is a new text file, for which no other schema information exists, these properties define the schema.
  2. If this is an existing text file, these properties provide an "override" of the schema information that's stored in the file.
For example, the columns in the file are named 'ResultX', 'ResultY' and 'ResultZ', but you want them to be named 'X', 'Y' and 'Z' within the DataExporter.
If you don't specify any column information, the columns used in the DataExporter are the same as those defined in the database file.

ByConnection - technique

Generally, this technique is for connecting to a database that doesn't reside on your local computer, and/or that uses a different file format than is supported by the other techniques.

This technique provides the greatest degree of power and flexibility, but also requires the greatest level of expertise on your part.

The following properties define this technique.

ConnectionType: DataConnectionType

One of the enumerated values Odbc, OleDb, or SqlClient.

ConnectionString: string

A connection string that is valid to an ADO.NET data connection object of the specified connection type. For more information, please consult documentation for Microsoft's ADO.NET.

SqlSelectCommand: string

A Transact-SQL SELECT command that defines how the data in the DataExporter will correlate with the data in the database. (Even though a DataExporter is intended to update the database, this SELECT command is composed just as with the DataImporter node.) For more information, please consult documentation for Microsoft’s Transact-SQL language.